<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:include="include :: header('分配完成条件')" />
</head>
<body class="gray-bg">
<div class="container-div">
	<div class="row">
		<div class="col-sm-12 search-collapse">
			<form id="role-form">
				<input type="hidden" id="taskId" name="taskId" th:value="${fantasyTask.taskId}">
				<div class="select-list">
					<ul>
						<li>
							完成条件类型：
							<select name="type" th:with="type=${@dict.getType('fantasy_completion_condition_type')}">
								<option value="">所有</option>
								<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
							</select>
						</li>

						<li>
							<a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
							<a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
						</li>
					</ul>
				</div>
			</form>
		</div>

		<div class="btn-group-sm" id="toolbar" role="group">
			<a class="btn btn-success" onclick="selectCompletionCondition()" shiro:hasPermission="fantasy:fantasyCompletionCondition:add">
				<i class="fa fa-plus"></i> 分配完成条件
			</a>
			<a class="btn btn-danger btn-del" onclick="cancelAllocCompletionConditionAll()" shiro:hasPermission="fantasy:fantasyCompletionCondition:remove">
				<i class="fa fa-remove"></i> 批量取消分配
			</a>
			<a class="btn btn-warning" onclick="closeItem()">
				<i class="fa fa-reply-all"></i> 关闭
			</a>
		</div>

		<div class="col-sm-12 select-table table-striped">
			<table id="bootstrap-table" data-mobile-responsive="true"></table>
		</div>
	</div>
</div>
<th:block th:include="include :: footer" />
<script th:inline="javascript">
	var editFlag = [[${@permission.hasPermi('fantasy:fantasyCompletionCondition:edit')}]];
    var removeFlag = [[${@permission.hasPermi('fantasy:fantasyCompletionCondition:remove')}]];
    var prefix = ctx + "fantasy/fantasyTask/allocCompletionCondition";
	var completionAchieveDatas = [[${@dict.getType('fantasy_completion_condition_achieve')}]];
	var completionTypeDatas = [[${@dict.getType('fantasy_completion_condition_type')}]];

    $(function() {
        var options = {
            url: prefix + "/allocatedCompletionConditionList",
            queryParams: queryParams,
            sortName: "id",
            sortOrder: "desc",
            modalName: "完成条件",
            columns: [{
                checkbox: true
            },
			{
				field : 'completionId',
				title : '完成条件id',
				visible: true
			},
			{
				field : 'achieve',
				title : '完成条件是否达到',
				sortable: true,
				formatter: function(value, row, index) {
					return $.table.selectDictLabel(completionAchieveDatas, value);
				}
			},
			{
				field : 'type',
				title : '完成条件类型',
				sortable: true,
				formatter: function(value, row, index) {
					return $.table.selectDictLabel(completionTypeDatas, value);
				}
			},
			{
				field : 'value',
				title : '完成条件内容',
				sortable: true
			},
			{
				field : 'count',
				title : '变动值',
				sortable: true
			},
			{
				field : 'createTime',
				title : '创建时间',
				sortable: true
			},
			{
				field : 'updateTime',
				title : '更新时间',
				sortable: true
			},
			{
				field : 'remark',
				title : '备注信息',
				sortable: true
			},
			{
				title: '操作',
				align: 'center',
				formatter: function(value, row, index) {
					var actions = [];
					actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="cancelAllocCompletionCondition(\'' + row.completionId + '\')"><i class="fa fa-remove"></i>取消分配</a> ');
					return actions.join('');
				}
			}]
        };
        $.table.init(options);
    });

    function queryParams(params) {
        var search = $.table.queryParams(params);
        search.taskId = $("#taskId").val();
        return search;
    }

    /* 分配完成条件-选择完成条件 */
    function selectCompletionCondition() {
        var url = prefix + '/selectCompletionCondition/' + $("#taskId").val();
        $.modal.open("选择完成条件", url);
    }

    /* 分配完成条件-批量取消分配 */
    function cancelAllocCompletionConditionAll() {
        var rows = $.table.selectFirstColumns();
        if (rows.length == 0) {
            $.modal.alertWarning("请至少选择一条记录");
            return;
        }
        $.modal.confirm("确认要删除选中的" + rows.length + "条数据吗?", function() {
            var data = { "taskId": $("#taskId").val(), "completionIds": rows.join() };
            $.operate.submit(prefix + "/cancelAll", "post", "json", data);
        });
    }

    /* 分配完成条件-取消分配 */
    function cancelAllocCompletionCondition(completionId) {
        $.modal.confirm("确认要取消分配该完成条件吗？", function() {
            $.operate.post(prefix + "/cancel", { "taskId": $("#taskId").val(), "completionId": completionId });
        })
    }
</script>
</body>
</html>